"""
本文详细阐述了Assistant API中Thread类的各项功能，涵盖了线程的创建、检索、修改以及删除操作。
"""
# 创建线程
print('创建线程')
import json
from dashscope import Threads

thread = Threads.create(messages=[{"role": "user", "content": "How does AI work? Explain it in simple terms."}])
print(json.dumps(thread, default=lambda o: o.__dict__, sort_keys=True, indent=4))
thread_id = thread.id
# 检索线程
print('检索线程')
thread = Threads.retrieve(thread_id)
print(json.dumps(thread, default=lambda o: o.__dict__, sort_keys=True, indent=4))
# 修改线程
print('修改线程')
thread = Threads.update(thread_id,
                        metadata={'content': 'AI是怎么工作的? 请解释一下.'})
print(json.dumps(thread, default=lambda o: o.__dict__, sort_keys=True, indent=4))
# 删除线程
print('删除线程')
deleteResp = Threads.delete(thread_id)
print(json.dumps(deleteResp, default=lambda o: o.__dict__, sort_keys=True, indent=4))